﻿using BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace WebAPIUI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FoodController : ControllerBase
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        private readonly FoodBLL bll;

        public FoodController(FoodBLL bll)
        {
            this.bll = bll;
        }
        /// <summary>
        /// 显示食谱类的所有信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IQueryable<FoodType> Getall()
        {
            try
            {
                return bll.Getall();
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPost]
        /// <summary>
        /// 新增食谱信息
        /// </summary>
        /// <param name="info">食谱类</param>
        /// <returns></returns>
        public int Add(Food info)
        {
            try
            {
                return bll.Add(info);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示+查询
        /// </summary>
        /// <param name="name">食谱标题</param>
        /// <param name="tid">食谱类</param>
        /// <returns></returns>
        [HttpGet]
        public IQueryable<DTO> Show(string? name, int tid = -1)
        {
            try
            {
                return bll.Show(name, tid);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
